<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/logic/CustomCommand.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/DaoFactory.php';
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];
	
	/*
	 * Class to select a product by code
	 */
	class CommandSelectProductByCode extends CustomCommand {
		/*
		 * Constructor of the class
		 */
		public function __construct($pkCode) {
			$this -> pkProductCode = $pkCode;	
		}
		
		/*
		 * Method to execute to select a single product by code
		 */
		public function execute() {
			$daoFactory = DaoFactory :: getMySqlDaoFactory();
			$ipad = $daoFactory -> getMySqlProductAccessDao();			
			$sentence = $ipad -> selectProductByCode($this -> pkProductCode);
			
			while ($row = mysql_fetch_array($sentence)) {
				$product['name'][0] = $row['name'];
				$product['unit_cost'][0] = $row['unit_cost'];
				$product['unit_cost_currency'][0] = $row['unit_cost_currency'];
				$product['product_units'][0] = $row['product_units'];
			}			
			
			$this -> result = $product;
		}
	}
?>